package br.org.credfaz.sis.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import br.org.credfaz.sis.MysqlConnectionFactory;
import br.org.credfaz.sis.modelo.ContaCapital;

public class ContaCapitalDAO {
private final Connection connection;
	
	public ContaCapitalDAO(){
		try{
			connection = new MysqlConnectionFactory().getConnection();
		}catch (SQLException e){
			throw new RuntimeException(e);
		}
	}
	
	public void apaga(){
		String sql = "delete from contacapital";
		PreparedStatement stmt;
		try{
			stmt = connection.prepareStatement(sql);
			
			stmt.execute();
			
		}catch (SQLException e){
			throw new RuntimeException(e);
		}
	}
	
	public void adiciona(ContaCapital contacapital){
		String sql = "insert into contacapital (nummatricula, idcliente," +
				"codtiposituacaoassociado, datamatricula, numcontacorrente, valorsaldoatuinteg)" +
				" values (?, ?, ?, ?, ?, ?)";
		PreparedStatement stmt;
		try{
			stmt = connection.prepareStatement(sql);
			
			stmt.setLong(1, contacapital.getNummatricula());
			stmt.setLong(2, contacapital.getIdcliente());
			stmt.setInt(3, contacapital.getCodtiposituacaoassociado());
			stmt.setDate(4, contacapital.getDatamatricula());
			stmt.setFloat(5, contacapital.getNumcontacorrente());
			stmt.setFloat(6, contacapital.getValorsaldoatuinteg());
			
			
			stmt.execute();
			
		}catch (SQLException e){
			throw new RuntimeException(e);
		}
	}

}
